<%--
  Created by IntelliJ IDEA.
  User: gaosubo
  Date: 2020/8/19
  Time: 13:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <title>人员权限设置</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=10,chrome=1">
        <meta name="viewport"
              content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
        <link rel="stylesheet" type="text/css" href="/lib/layui/layui/css/layui.css"/>
        <script type="text/javascript" src="/js/news/jquery-1.9.1.js"></script>
        <script src="/js/base/base.js" type="text/javascript" charset="utf-8"></script>
        <script src="../../js/jquery/jquery.cookie.js"></script>
        <script src="/lib/jQuery-File-Upload-master/jquery.ui.widget.js" type="text/javascript" charset="utf-8"></script>
        <script src="/lib/jQuery-File-Upload-master/jquery.iframe-transport.js" type="text/javascript" charset="utf-8"></script>
        <script src="/lib/jQuery-File-Upload-master/jquery.fileupload.js" type="text/javascript" charset="utf-8"></script>
        <script type="text/javascript" src="/js/common/fileupload.js"></script>
        <script type="text/javascript" src="/lib/layui/layui/layui.js"></script>
        <script type="text/javascript" src="/lib/layui/layui/layui.all.js"></script>
    </head>
    <style>
        .mbox {
            padding: 8px
        }
        .item img {
            height: 27px;
        }
        .btn {
            height: 30px;
        }

        .btn button {
            float: right;
        }
        .lab{
            margin-left: 12px;
            width:126px;
        }
        .left{
            margin-left: -10px;
            width: 90px;
            text-align: center;
            white-space: pre-wrap;
        }
        .rig1{
            float: right;
            width: 66px;
            height: 35px;
            margin-top: -74px;
        }
        .rig{
            float:right;
            margin: 0px -56px 0px 10px;
            width: 66px;height: 35px;
            line-height: 37px
        }

        .species{
            margin-left: 55px;
        }
        .species1{
            margin-left: 0px;
        }
    </style>
</head>
<body>
<div class="mbox">
    <div class="item">
        <img src="/img/commonTheme/theme6/flow_run_title.png" alt="" style="margin: 0 5px 0 20px;"> <span
            style="font-size: 22px;display: inline-block;vertical-align: middle;">人员权限设置</span>
    </div>
    <hr class="layui-bg-blue">
    <div class="btn">
        <button type="button" class="layui-btn layui-btn-sm add" style="background: #2b7fe0;margin-left:20px"><i
                class="layui-icon layui-icon-addition" style="vertical-align: inherit"></i>新建
        </button>
    </div>
    <table class="layui-hide" id="test" lay-filter="test"></table>
</div>

</body>
</html>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
    layui.use(['table', 'form', 'laydate'], function () {
        var table = layui.table,
            form = layui.form,
            laydate = layui.laydate
        var tableInt = table.render({
            elem: '#test'
            , url: '/HrEvaluatePriv/findHrEvaluatePriv'
            , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            , defaultToolbar: [''],
            parseData: function(res){ //res 即为原始返回的数据
                return {
                    "code":0, //解析接口状态
                    "data": res.obj, //解析数据列表，
                    "count": res.totleNum, //解析数据长度
                };
            }
            , title: '用户数据表'
            , cols: [[
                {field: 'privType', title: '类型',templet: function(d){
                        if(d.privType=='1'){
                            return '查看权限'
                        }else{
                            return '评价权限'
                        }
                    }}
                , {field: 'viewOrEvaluateUserNames', title: '查看或评价人'}
                , {field: 'privUserNames', title: '被查看或被评价人'}
                , {field: 'privDeptNames', title: '被查看或被评价部门'}
                , {field: 'type', title: '操作', toolbar: '#barDemo'}
            ]]
            // , page: true
        });

        var mobiletype = false;
        if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
            mobiletype = true;
        } else if (/(Android)/i.test(navigator.userAgent)) {
            mobiletype = true;
        }

        //新建
        $('.add').click(function () {
            creat(0)
        });
        var datas
        //监听行工具事件
        table.on('tool(test)', function(obj){
            datas = obj.data;
            var privId=datas.privId
            if(obj.event === 'del'){
                layer.confirm('真的删除当前数据吗？', function (index) {
                    $.ajax({
                        type: 'get',
                        url: '/HrEvaluatePriv/delEvaluatePriv?privId='+privId,
                        dataType: 'json',
                        success: function (res) {
                            if (res.msg == 'ok') {
                                layer.msg('删除成功！', {icon: 1});
                                tableInt.reload()
                                layer.closeAll();
                            }
                        }
                    })
                });
            } else if(obj.event === 'edit'){
                creat(1,datas,privId)
            }
        });
        /*新建和编辑的方法*/
        function creat(type,data,privId) {
            if (mobiletype) {
                var width = '95%';
                var height = '90%';
            }else{
                var width = '30%';
                var height = '70%';
            }
            if (type == '0') {
                var title = '新建';
            } else {
                var title = '编辑';
            }

            layer.open({
                type: 1,
                title: title,
                btn: ['确定', '取消'],
                shade: 0.5,
                maxmin: true, //开启最大化最小化按钮
                // area: ['30%', '60%'],
                area: [width, height],
                content: '<div class="cont">\n' +
                    '    <form class="layui-form " action="">\n' +
                    '        <div class="layui-form-item">\n' +
                    '            <label class="layui-form-label species">类型</label>\n' +
                    '            <div class="layui-input-block">\n' +
                    '                <input type="radio" name="privType" value="1" title="查看权限" checked>\n' +
                    '                <input type="radio" name="privType" value="2" title="评价权限">\n' +
                    '            </div>\n' +
                    '        </div>\n' +
                    '        <div class="layui-form-item">\n' +
                    '            <div class="layui-inline" style="margin-top: 10px;">\n' +
                    '                <label class="layui-form-label lab">查看或评价人</label>\n' +
                    '                <div class="layui-input-inline" style="width: 170px">\n' +
                    '                    <textarea  id="rescueUser" user_id=""  class="layui-textarea" disabled style="background-color: #f2f2f2;"></textarea>\n'+
                    '                </div>\n' +
                    '                <div class="rig">\n' +
                    '                    <a href="javascript:;" style="color:#1E9FFF" class="addExecute">添加</a>\n' +
                    '                    <a href="javascript:;" style="color:#1E9FFF" class="clearExecute">清空</a>\n' +
                    '                </div>\n' +
                    '            </div>\n' +
                    '        </div>\n' +
                    '        <div class="layui-form-item">\n' +
                    '            <div class="layui-inline" style="margin-top: 10px;">\n' +
                    '                <label class="layui-form-label lab">被查看或被评价人</label>\n' +
                    '                <div class="layui-input-inline" style="width: 170px">\n' +
                    '                    <textarea  id="rescue" user_id=""  class="layui-textarea" disabled style="background-color: #f2f2f2;"></textarea>\n'+
                    '                </div>\n' +
                    '                <div class="rig">\n' +
                    '                    <a href="javascript:;" style="color:#1E9FFF" class="Execute">添加</a>\n' +
                    '                    <a href="javascript:;" style="color:#1E9FFF" class="clears">清空</a>\n' +
                    '                </div>\n' +
                    '            </div>\n' +
                    '        </div>\n' +
                    '        <div class="layui-form-item">\n' +
                    '            <div class="layui-inline" style="margin-top: 10px;">\n' +
                    '                <label class="layui-form-label lab">被查看或被评价部门</label>\n'+
                    '                <div class="layui-input-inline" style="width: 170px">\n' +
                    '                    <textarea  id="PRIV_DEPTS"  class="layui-textarea" disabled style="background-color: #f2f2f2;"></textarea>\n'+
                    '                </div>\n' +
                    '                <div class="rig">\n' +
                    '                    <a href="javascript:;" style="color:#1E9FFF" class="depExecute">添加</a>\n' +
                    '                    <a href="javascript:;" style="color:#1E9FFF" class="depclears">清空</a>\n' +
                    '                </div>\n' +
                    '            </div>\n' +
                    '        </div>\n' +
                    '    </form>\n' +
                    '</div>',
                success:function (res) {
                    form.render();
                    if (mobiletype) {
                        $('.layui-form-label').css('white-space','pre-wrap')
                        $('.lab').addClass('left')
                        $('.rig').addClass('rig1')
                        $('.species').addClass('species1')
                        $('.lab').removeClass('lab')
                        $('.rig').removeClass('rig')
                        $('.species').removeClass('species')

                    }

                    //查看评价人
                    $(".addExecute").on("click",function(){
                        user_id = "rescueUser";
                        $.popWindow("/common/selectUser");
                    });
                    $('.clearExecute').click(function () {
                        $("#rescueUser").val("");
                        $("#rescueUser").attr('username','');
                        $("#rescueUser").attr('dataid','');
                        $("#rescueUser").attr('user_id','');
                        $("#rescueUser").attr('userprivname','');
                    });

                    //被查看或被评价人
                    $(".Execute").on("click",function(){
                        user_id = "rescue";
                        $.popWindow("/common/selectUser");
                    });
                    $('.clears').click(function () {
                        $("#rescue").val("");
                        $("#rescue").attr('username','');
                        $("#rescue").attr('dataid','');
                        $("#rescue").attr('user_id','');
                        $("#rescue").attr('userprivname','');
                    });

                    //被查看或被评价部门
                    $(".depExecute").on("click",function(){
                        dept_id = "PRIV_DEPTS";
                        $.popWindow("/common/selectDept");
                    });
                    $('.depclears').click(function () {
                        $("#PRIV_DEPTS").val("");
                        $("#PRIV_DEPTS").attr('deptname','');
                        $("#PRIV_DEPTS").attr('deptid','');
                    });


                    if(type==1){
                        // if (mobiletype) {
                        //     $('.lab').addClass('left')
                        //     $('.lab').removeClass('lab')
                        //     $('.rig').removeClass('rig')
                        //     $('.species').removeClass('species')
                        //
                        // }
                        $('#rescueUser').val(datas.viewOrEvaluateUserNames);
                        $("#rescueUser").attr('user_id',datas.viewOrEvaluateUsers);

                        $('#rescue').val(datas.privUserNames)
                        $("#rescue").attr('user_id',datas.privUsers);

                        $('#PRIV_DEPTS').val(datas.privDeptNames);
                        $("#PRIV_DEPTS").attr('deptid',datas.privDepts);


                        //类型
                        $('input[name=privType][value="1"]').attr("checked", datas.privType == "1" ? true : false);
                        $('input[name=privType][value="2"]').attr("checked", datas.privType == "2" ? true : false);
                        form.render()
                    }

                },
                yes:function (index) {
                    var data={
                        privType:$('input[name="privType"]:checked').val(),
                        viewOrEvaluateUsers:$('#rescueUser').attr('user_id'),
                        privUsers:$('#rescue').attr('user_id'),
                        privDepts:$('#PRIV_DEPTS').attr('deptid')
                    }
                    if(type == 0){
                        var url = '/HrEvaluatePriv/insertHrEvaluatePriv'
                    }else{
                        var url = '/HrEvaluatePriv/editEvaluatePriv'
                        data.privId =privId
                    }
                    $.ajax({
                        url:url,
                        data:data,
                        dataType:'json',
                        type:'post',
                        success:function (res) {
                            layer.msg('新增成功')
                            tableInt.reload()
                            layer.closeAll();
                        }
                    })


                }
            })
        }

    });

</script>
